import os
import sys
import re

if __name__ == '__main__':
    handler = sys.stdin
    word_dict = {}
    for line in handler:
        f_map_line = line.strip().split('(')[1].split(')')[0]
        # print(f_map_line)
        host = f_map_line.split(',')[2].strip()
        # print(host)

        friends_s = set()
        if host not in word_dict.keys():

            friends_s.add(f_map_line.split(',')[0].strip())
            friends_s.add(f_map_line.split(',')[1].strip())
            # print(friends_s)
            word_dict[host] = friends_s
        else:
            friends_s = word_dict[host]
            friends_s.add(f_map_line.split(',')[0].strip())
            friends_s.add(f_map_line.split(',')[1].strip())
        # print(friends_s)

    for w in word_dict:
        print(w, word_dict[w])